<!DOCTYPE html>










































































<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link rel="shortcut icon" type="image/x-icon" href="../../../../../../favicon.ico" />
<title>GoogleAuthUtil | Android Developers</title>

<!-- STYLESHEETS -->
<link rel="stylesheet"
href="http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" title="roboto">
<link href="../../../../../../assets/css/default.css" rel="stylesheet" type="text/css">


<!-- FULLSCREEN STYLESHEET -->
<link href="../../../../../../assets/css/fullscreen.css" rel="stylesheet" class="fullscreen"
type="text/css">


<!-- JAVASCRIPT -->
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script src="../../../../../../assets/js/global-libraries-combined.js" type="text/javascript"></script>
<script type="text/javascript">
  var toRoot = "../../../../../../";
</script>
<script src="../../../../../../assets/js/docs.js" type="text/javascript"></script>

<script src="../../../../../../navtree_data.js" type="text/javascript"></script>

</head>
<body class="gc-documentation 
  develop" itemscope itemtype="http://schema.org/Article">
  <div id="doc-api-level" class="" style="display:none"></div>
  <a name="top"></a>

    <!-- Header -->
    <div id="header">
        <div class="wrap" id="header-wrap">
          <div class="col-3 logo">
          <a href="../../../../../../index.html">
            <img src="../../../../../../assets/images/dac_logo.png" width="123" height="25" alt="Android Developers" />
          </a>
          <div class="btn-quicknav" id="btn-quicknav">
          	<a href="#" class="arrow-inactive">Quicknav</a>
			      <a href="#" class="arrow-active">Quicknav</a>
          </div>
          </div>
            <ul class="nav-x col-9">
                <li class="design">
                  <a href="../../../../../../design/index.html" 
                  zh-TW-lang="設計"
                  zh-CN-lang="设计"
                  ru-lang="Проектирование"
                  ko-lang="디자인"
                  ja-lang="設計"
                  es-lang="Diseñar"               
                  >Design</a></li>
                <li class="develop"><a href="../../../../../../develop/index.html" class="selected"
                  zh-TW-lang="開發"
                  zh-CN-lang="开发"
                  ru-lang="Разработка"
                  ko-lang="개발"
                  ja-lang="開発"
                  es-lang="Desarrollar"               
                  >Develop</a></li>
                <li class="distribute last"><a href="../../../../../../distribute/index.html" 
                  zh-TW-lang="發佈"
                  zh-CN-lang="分发"
                  ru-lang="Распространение"
                  ko-lang="배포"
                  ja-lang="配布"
                  es-lang="Distribuir"               
                  >Distribute</a></li>
            </ul>
            
            <!-- New Search -->
            <div class="menu-container">
            <div class="moremenu">
    <div id="more-btn"></div>
  </div>
  <div class="morehover" id="moremenu">
    <div class="top"></div>
    <div class="mid">
      <div class="header">Links</div>
      <ul>
        <li><a href="https://play.google.com/apps/publish/">Google Play Developer Console</a></li>
        <li><a href="http://android-developers.blogspot.com/">Android Developers Blog</a></li>
        <li><a href="../../../../../../about/index.html">About Android</a></li>
      </ul>
      <div class="header">Android Sites</div>
      <ul>
        <li><a href="http://www.android.com">Android.com</a></li>
        <li class="active"><a>Android Developers</a></li>
        <li><a href="http://source.android.com">Android Open Source Project</a></li>
      </ul>
      <!-- <div class="header">Support</div>
      <ul>
        <li><a href="../../../../../../support.html">Developer Support</a></li>
      </ul> -->
      <div class="header">Languages</div>
        <div id="language" class="locales">
          <select name="language" onChange="changeLangPref(this.value, true)">
              <option value="en">English</option>
              <option value="es">Español</option>
              <option value="ja">日本語</option>
              <option value="ko">한국어</option>
              <option value="ru">Русский</option>
              <option value="zh-CN">中文 (中国)</option>
              <option value="zh-TW">中文 (台灣)</option>
          </select>
        </div>
      <script type="text/javascript">
        <!--  
        loadLangPref();  
          //-->
      </script>
      <br class="clearfix" />
    </div>
    <div class="bottom"></div>
  </div>
  <div class="search" id="search-container">
    <div class="search-inner">
      <div id="search-btn"></div>
      <div class="left"></div>
      <form onsubmit="return submit_search()">
        <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q"
onfocus="search_focus_changed(this, true)" onblur="search_focus_changed(this, false)"
onkeydown="return search_changed(event, true, '../../../../../../')" 
onkeyup="return search_changed(event, false, '../../../../../../')" />
      </form>
      <div class="right"></div>
        <a class="close hide">close</a>
        <div class="left"></div>
        <div class="right"></div>
    </div>
  </div>
  <div id="search_filtered_wrapper">
    <div id="search_filtered_div" class="no-display">
        <ul id="search_filtered">
        </ul>
    </div>
  </div>
  
  </div>
  <!-- /New Search>
          
          
          <!-- Expanded quicknav -->
           <div id="quicknav" class="col-9">
                <ul>
                    <li class="design">
                      <ul>
                        <li><a href="../../../../../../design/index.html">Get Started</a></li>
                        <li><a href="../../../../../../design/style/index.html">Style</a></li>
                        <li><a href="../../../../../../design/patterns/index.html">Patterns</a></li>
                        <li><a href="../../../../../../design/building-blocks/index.html">Building Blocks</a></li>
                        <li><a href="../../../../../../design/downloads/index.html">Downloads</a></li>
                        <li><a href="../../../../../../design/videos/index.html">Videos</a></li>
                      </ul>
                    </li>
                    <li class="develop">
                      <ul>
                        <li><a href="../../../../../../training/index.html"
                          zh-TW-lang="訓練課程"
                          zh-CN-lang="培训"
                          ru-lang="Курсы"
                          ko-lang="교육"
                          ja-lang="トレーニング"
                          es-lang="Capacitación"               
                          >Training</a></li>
                        <li><a href="../../../../../../guide/components/index.html"
                          zh-TW-lang="API 指南"
                          zh-CN-lang="API 指南"
                          ru-lang="Руководства по API"
                          ko-lang="API 가이드"
                          ja-lang="API ガイド"
                          es-lang="Guías de la API"               
                          >API Guides</a></li>
                        <li><a href="../../../../../../reference/packages.html"
                          zh-TW-lang="參考資源"
                          zh-CN-lang="参考"
                          ru-lang="Справочник"
                          ko-lang="참조문서"
                          ja-lang="リファレンス"
                          es-lang="Referencia"               
                          >Reference</a></li>
                        <li><a href="../../../../../../tools/index.html"
                          zh-TW-lang="相關工具"
                          zh-CN-lang="工具"
                          ru-lang="Инструменты"
                          ko-lang="도구"
                          ja-lang="ツール"
                          es-lang="Herramientas"               
                          >Tools</a>
                          <ul><li><a href="../../../../../../sdk/index.html">Get the SDK</a></li></ul>
                        </li>
                        <li><a href="../../../../../../google/index.html">Google Services</a>
                        </li>
                      </ul>
                    </li>
                    <li class="distribute last">
                      <ul>
                        <li><a href="../../../../../../distribute/index.html">Google Play</a></li>
                        <li><a href="../../../../../../distribute/googleplay/publish/index.html">Publishing</a></li>
                        <li><a href="../../../../../../distribute/googleplay/promote/index.html">Promoting</a></li>
                        <li><a href="../../../../../../distribute/googleplay/quality/index.html">App Quality</a></li>
                        <li><a href="../../../../../../distribute/googleplay/spotlight/index.html">Spotlight</a></li>
                        <li><a href="../../../../../../distribute/open.html">Open Distribution</a></li>
                      </ul>
                    </li>
                </ul>
          </div>
          <!-- /Expanded quicknav -->
        </div>
    </div>
    <!-- /Header -->
    
    
  <div id="searchResults" class="wrap" style="display:none;">
          <h2 id="searchTitle">Results</h2>
          <div id="leftSearchControl" class="search-control">Loading...</div>
  </div>
    
    
    

    <!-- Secondary x-nav -->
    <div id="nav-x">
        <div class="wrap">
            <ul class="nav-x col-9 develop" style="width:100%">
                <li><a href="../../../../../../training/index.html" 
                  zh-TW-lang="訓練課程"
                  zh-CN-lang="培训"
                  ru-lang="Курсы"
                  ko-lang="교육"
                  ja-lang="トレーニング"
                  es-lang="Capacitación"               
                  >Training</a></li>
                <li><a href="../../../../../../guide/components/index.html" 
                  zh-TW-lang="API 指南"
                  zh-CN-lang="API 指南"
                  ru-lang="Руководства по API"
                  ko-lang="API 가이드"
                  ja-lang="API ガイド"
                  es-lang="Guías de la API"               
                  >API Guides</a></li>
                <li><a href="../../../../../../reference/packages.html" class="selected"
                  zh-TW-lang="參考資源"
                  zh-CN-lang="参考"
                  ru-lang="Справочник"
                  ko-lang="참조문서"
                  ja-lang="リファレンス"
                  es-lang="Referencia"               
                  >Reference</a></li>
                <li><a href="../../../../../../tools/index.html" 
                  zh-TW-lang="相關工具"
                  zh-CN-lang="工具"
                  ru-lang="Инструменты"
                  ko-lang="도구"
                  ja-lang="ツール"
                  es-lang="Herramientas"
                  >Tools</a></li>
                <li><a href="../../../../../../google/index.html" 
                  >Google Services</a>
                </li>
            </ul>
        </div>
        
    </div>
    <!-- /Sendondary x-nav -->

  


  <div class="wrap clearfix" id="body-content">
    <div class="col-4" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement">
      <div id="devdoc-nav">

<a class="totop" href="#top" data-g-event="left-nav-top">to top</a>
      <div id="api-nav-header">
        <div id="api-level-toggle">
          <label for="apiLevelCheckbox" class="disabled">API level: </label>
          <div class="select-wrapper">
            <select id="apiLevelSelector">
              <!-- option elements added by buildApiLevelSelector() -->
            </select>
          </div>
        </div><!-- end toggle -->
        <div id="api-nav-title">Android APIs</div>
        </div><!-- end nav header -->
      <script>
        var SINCE_DATA = [  ];
        buildApiLevelSelector();
      </script>
                  
      <div id="swapper">
        <div id="nav-panels">
          <div id="resize-packages-nav">
            <div id="packages-nav" class="scroll-pane">

              <ul>
              	
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/package-summary.html">com.google.android.gms</a></li>
    <li class="selected api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/auth/package-summary.html">com.google.android.gms.auth</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/common/package-summary.html">com.google.android.gms.common</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/common/data/package-summary.html">com.google.android.gms.common.data</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/common/images/package-summary.html">com.google.android.gms.common.images</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/maps/package-summary.html">com.google.android.gms.maps</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/maps/model/package-summary.html">com.google.android.gms.maps.model</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/panorama/package-summary.html">com.google.android.gms.panorama</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/plus/package-summary.html">com.google.android.gms.plus</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/plus/model/moments/package-summary.html">com.google.android.gms.plus.model.moments</a></li>
    <li class="api apilevel-">
  <a href="../../../../../../reference/com/google/android/gms/plus/model/people/package-summary.html">com.google.android.gms.plus.model.people</a></li>
              </ul><br/>

            </div> <!-- end packages-nav -->
          </div> <!-- end resize-packages -->
          <div id="classes-nav" class="scroll-pane">



            <ul>
              
              
    <li><h2>Classes</h2>
      <ul>
          <li class="selected api apilevel-"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html">GoogleAuthUtil</a></li>
      </ul>
    </li>
              
              
    <li><h2>Exceptions</h2>
      <ul>
          <li class="api apilevel-"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></li>
          <li class="api apilevel-"><a href="../../../../../../reference/com/google/android/gms/auth/GooglePlayServicesAvailabilityException.html">GooglePlayServicesAvailabilityException</a></li>
          <li class="api apilevel-"><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableAuthException.html">UserRecoverableAuthException</a></li>
          <li class="api apilevel-"><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableNotifiedException.html">UserRecoverableNotifiedException</a></li>
      </ul>
    </li>
              
            </ul><br/>
        

          </div><!-- end classes -->
        </div><!-- end nav-panels -->
        <div id="nav-tree" style="display:none" class="scroll-pane">
          <div id="tree-list"></div>
        </div><!-- end nav-tree -->
      </div><!-- end swapper -->
      <div id="nav-swap">
      <a class="fullscreen">fullscreen</a>
      <a href='#' onclick='swapNav();return false;'><span id='tree-link'>Use Tree Navigation</span><span id='panel-link' style='display:none'>Use Panel Navigation</span></a>
      </div>
    </div> <!-- end devdoc-nav -->
    </div> <!-- end side-nav -->
    <script type="text/javascript">
      // init fullscreen based on user pref
      var fullscreen = readCookie("fullscreen");
      if (fullscreen != 0) {
        if (fullscreen == "false") {
          toggleFullscreen(false);
        } else {
          toggleFullscreen(true);
        }
      }
      // init nav version for mobile
      if (isMobile) {
        swapNav(); // tree view should be used on mobile
        $('#nav-swap').hide();
      } else {
        chooseDefaultNav();
        if ($("#nav-tree").is(':visible')) {
          init_default_navtree("../../../../../../");
        }
      }
      // scroll the selected page into view
      $(document).ready(function() {
        scrollIntoView("packages-nav");
        scrollIntoView("classes-nav");
        });
    </script>

     
    <script>
      $(document).ready(function() {
        changeDocLang(getLangPref());
        });
    </script>



<div class="col-12"  id="doc-col">

<div id="api-info-block">



  
   
  
  
  
  


<div class="sum-details-links">

Summary:





  <a href="#constants">Constants</a>
  







  &#124; <a href="#pubmethods">Methods</a>
  



  &#124; <a href="#inhmethods">Inherited Methods</a>

&#124; <a href="#" onclick="return toggleAllClassInherited()" id="toggleAllClassInherited">[Expand All]</a>

</div><!-- end sum-details-links -->
<div class="api-level">
  
  
  

</div>
</div><!-- end api-info-block -->


<!-- ======== START OF CLASS DATA ======== -->

<div id="jd-header">
    public
     
    final 
    
    class
<h1 itemprop="name">GoogleAuthUtil</h1>



  
    extends <a href="http://developer.android.com/reference/java/lang/Object.html">Object</a><br/>
  
  
  

  
  
  


</div><!-- end header -->

<div id="naMessage"></div>

<div id="jd-content" class="api apilevel-">
<table class="jd-inheritance-table">


    <tr>
         	
        <td colspan="2" class="jd-inheritance-class-cell"><a href="http://developer.android.com/reference/java/lang/Object.html">java.lang.Object</a></td>
    </tr>
    

    <tr>
        
            <td class="jd-inheritance-space">&nbsp;&nbsp;&nbsp;&#x21b3;</td>
         	
        <td colspan="1" class="jd-inheritance-class-cell">com.google.android.gms.auth.GoogleAuthUtil</td>
    </tr>
    

</table>







<div class="jd-descr">


<h2>Class Overview</h2>
<p itemprop="articleBody">GoogleAuthUtil provides static utility methods to acquire and invalidate
 authentication tokens.

 <pre>
   public void onCreate {
       // onCreate is called on the main thread, so you must do the work in
       // a background thread, which AsyncTask makes easy to do.
       getAndUseAuthTokenInAsyncTask();
   }

   ...

   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       if (requestCode == MY_ACTIVITYS_AUTH_REQUEST_CODE) {
           if (resultCode == RESULT_OK) {
               getAndUseAuthTokenInAsyncTask();
           }
       }
   }

   // Example of how to use the GoogleAuthUtil in a blocking, non-main thread context
   void getAndUseAuthTokenBlocking() {
       try {
          // Retrieve a token for the given account and scope. It will always return either
          // a non-empty String or throw an exception.
          final String token = <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html">GoogleAuthUtil</a></code>.<code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context, java.lang.String, java.lang.String)">getToken(Context, String, String)</a></code>(context, email, scope);
          // Do work with token.
          ...
          if (server indicates token is invalid) {
              // invalidate the token that we found is bad so that <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html">GoogleAuthUtil</a></code> won't
              // return it next time (it may have cached it)
              <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html">GoogleAuthUtil</a></code>.<code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#invalidateToken(android.content.Context, java.lang.String)">invalidateToken(Context, String)</a></code>(context, token);
              // consider retrying getAndUseTokenBlocking() once more
              return;
          }
          return;
       } catch (GooglePlayServicesAvailabilityException playEx) {
         Dialog alert = GooglePlayServicesUtil.getErrorDialog(
             playEx.getConnectionStatusCode(),
             this,
             MY_ACTIVITYS_AUTH_REQUEST_CODE);
         ...
       } catch (UserRecoverableAuthException userAuthEx) {
          // Start the user recoverable action using the intent returned by
          // <code><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableAuthException.html#getIntent()">getIntent()</a></code>
          myActivity.startActivityForResult(
                  userAuthEx.getIntent(),
                  MY_ACTIVITYS_AUTH_REQUEST_CODE);
          return;
       } catch (IOException transientEx) {
          // network or server error, the call is expected to succeed if you try again later.
          // Don't attempt to call again immediately - the request is likely to
          // fail, you'll hit quotas or back-off.
          ...
          return;
       } catch (GoogleAuthException authEx) {
          // Failure. The call is not expected to ever succeed so it should not be
          // retried.
          ...
          return;
       }
   }

   // Example of how to use AsyncTask to call blocking code on a background thread.
   void getAndUseAuthTokenInAsyncTask() {
       AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
           &#64Override
           protected Void doInBackground(Void... params) {
               getAndUseAuthTokenBlocking();
           }
       };
       task.execute((Void)null);
   }
 </pre>

</p>





</div><!-- jd-descr -->
















<div class="jd-descr">


<h2>Summary</h2>













<!-- =========== ENUM CONSTANT SUMMARY =========== -->
<table id="constants" class="jd-sumtable"><tr><th colspan="12">Constants</th></tr>


    
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><a href="http://developer.android.com/reference/java/lang/String.html">String</a></td>
        <td class="jd-linkcol"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#GOOGLE_ACCOUNT_TYPE">GOOGLE_ACCOUNT_TYPE</a></td>
        <td class="jd-descrcol" width="100%"></td>
    </tr>
    
    
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><a href="http://developer.android.com/reference/java/lang/String.html">String</a></td>
        <td class="jd-linkcol"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#KEY_HANDLE_NOTIFICATION">KEY_HANDLE_NOTIFICATION</a></td>
        <td class="jd-descrcol" width="100%"></td>
    </tr>
    
    
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><a href="http://developer.android.com/reference/java/lang/String.html">String</a></td>
        <td class="jd-linkcol"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#KEY_REQUEST_VISIBLE_ACTIVITIES">KEY_REQUEST_VISIBLE_ACTIVITIES</a></td>
        <td class="jd-descrcol" width="100%">Bundle key for specifying which user's app activity (moment) types can be written to Google.</td>
    </tr>
    
    

</table>
















<!-- ========== METHOD SUMMARY =========== -->
<table id="pubmethods" class="jd-sumtable"><tr><th colspan="12">Public Methods</th></tr>



	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            static
            
            <a href="http://developer.android.com/reference/java/lang/String.html">String</a></nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context, java.lang.String, java.lang.String)">getToken</a></span>(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope)</nobr>
        
        <div class="jd-descrdiv">Authenticates the user and returns a valid Google authentication token,
 or throws an exception if there was an error getting a token.</div>
  
  </td></tr>


	 
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            static
            
            <a href="http://developer.android.com/reference/java/lang/String.html">String</a></nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle)">getToken</a></span>(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> extras)</nobr>
        
        <div class="jd-descrdiv">Authenticates the user and returns a valid Google authentication token, or throws an
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code> if there was an error while getting the token.</div>
  
  </td></tr>


	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            static
            
            <a href="http://developer.android.com/reference/java/lang/String.html">String</a></nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getTokenWithNotification(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle)">getTokenWithNotification</a></span>(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> extras)</nobr>
        
        <div class="jd-descrdiv">Authenticates the user and returns a valid Google authentication token, or throws an
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code> if there was an error while getting the token.</div>
  
  </td></tr>


	 
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            static
            
            <a href="http://developer.android.com/reference/java/lang/String.html">String</a></nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getTokenWithNotification(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle, android.content.Intent)">getTokenWithNotification</a></span>(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> extras, <a href="http://developer.android.com/reference/android/content/Intent.html">Intent</a> callback)</nobr>
        
        <div class="jd-descrdiv">Authenticates the user and returns a valid Google authentication token, or throws an
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code> if there was an error while getting the token.</div>
  
  </td></tr>


	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            static
            
            <a href="http://developer.android.com/reference/java/lang/String.html">String</a></nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getTokenWithNotification(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle, java.lang.String, android.os.Bundle)">getTokenWithNotification</a></span>(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> extras, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> authority, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> syncBundle)</nobr>
        
        <div class="jd-descrdiv">Authenticates the user and returns a valid Google authentication token, or throws an
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code> if there was an error while getting the token.</div>
  
  </td></tr>


	 
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            static
            
            void</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad"><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#invalidateToken(android.content.Context, java.lang.String)">invalidateToken</a></span>(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> token)</nobr>
        
        <div class="jd-descrdiv">Invalidates the specified token with respect to the <code><a href="../../../../../../http://developer.android.com/reference/android/content/Context.html">Context</a></code>.</div>
  
  </td></tr>



</table>







<!-- ========== METHOD SUMMARY =========== -->
<table id="inhmethods" class="jd-sumtable"><tr><th>
  <a href="#" class="toggle-all" onclick="return toggleAllInherited(this, null)">[Expand]</a>
  <div style="clear:left;">Inherited Methods</div></th></tr>


<tr class="api apilevel-" >
<td colspan="12">
  <a href="#" onclick="return toggleInherited(this, null)" id="inherited-methods-java.lang.Object" class="jd-expando-trigger closed"
          ><img id="inherited-methods-java.lang.Object-trigger"
          src="../../../../../../assets/images/triangle-closed.png"
          class="jd-expando-trigger-img" /></a>
From class

  <a href="http://developer.android.com/reference/java/lang/Object.html">java.lang.Object</a>

<div id="inherited-methods-java.lang.Object">
  <div id="inherited-methods-java.lang.Object-list"
        class="jd-inheritedlinks">
  </div>
  <div id="inherited-methods-java.lang.Object-summary" style="display: none;">
    <table class="jd-sumtable-expando">
    


	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            
            
            <a href="http://developer.android.com/reference/java/lang/Object.html">Object</a></nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">clone</span>()</nobr>
        
  </td></tr>


	 
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            
            
            boolean</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">equals</span>(<a href="http://developer.android.com/reference/java/lang/Object.html">Object</a> arg0)</nobr>
        
  </td></tr>


	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            
            
            void</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">finalize</span>()</nobr>
        
  </td></tr>


	 
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            final
            
            
            <a href="http://developer.android.com/reference/java/lang/Class.html">Class</a>&lt;?&gt;</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">getClass</span>()</nobr>
        
  </td></tr>


	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            
            
            int</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">hashCode</span>()</nobr>
        
  </td></tr>


	 
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            final
            
            
            void</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">notify</span>()</nobr>
        
  </td></tr>


	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            final
            
            
            void</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">notifyAll</span>()</nobr>
        
  </td></tr>


	 
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            
            
            
            <a href="http://developer.android.com/reference/java/lang/String.html">String</a></nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">toString</span>()</nobr>
        
  </td></tr>


	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            final
            
            
            void</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">wait</span>()</nobr>
        
  </td></tr>


	 
    <tr class=" api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            final
            
            
            void</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">wait</span>(long arg0, int arg1)</nobr>
        
  </td></tr>


	 
    <tr class="alt-color api apilevel-" >
        <td class="jd-typecol"><nobr>
            
            
            final
            
            
            void</nobr>
        </td>
        <td class="jd-linkcol" width="100%"><nobr>
        <span class="sympad">wait</span>(long arg0)</nobr>
        
  </td></tr>


</table>
  </div>
</div>
</td></tr>


</table>


</div><!-- jd-descr (summary) -->

<!-- Details -->








<!-- XML Attributes -->


<!-- Enum Values -->


<!-- Constants -->


<!-- ========= ENUM CONSTANTS DETAIL ======== -->
<h2>Constants</h2>




<A NAME="GOOGLE_ACCOUNT_TYPE"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
        final 
        <a href="http://developer.android.com/reference/java/lang/String.html">String</a>
      </span>
        GOOGLE_ACCOUNT_TYPE
    </h4>
      <div class="api-level">
        
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p></p></div>

    
        <div class="jd-tagdata">
        <span class="jd-tagtitle">Constant Value: </span>
        <span>
            
                "com.google"
            
        </span>
        </div>
    
    </div>
</div>



<A NAME="KEY_HANDLE_NOTIFICATION"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
        final 
        <a href="http://developer.android.com/reference/java/lang/String.html">String</a>
      </span>
        KEY_HANDLE_NOTIFICATION
    </h4>
      <div class="api-level">
        
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p></p></div>

    
        <div class="jd-tagdata">
        <span class="jd-tagtitle">Constant Value: </span>
        <span>
            
                "handle_notification"
            
        </span>
        </div>
    
    </div>
</div>



<A NAME="KEY_REQUEST_VISIBLE_ACTIVITIES"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
        final 
        <a href="http://developer.android.com/reference/java/lang/String.html">String</a>
      </span>
        KEY_REQUEST_VISIBLE_ACTIVITIES
    </h4>
      <div class="api-level">
        
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p>Bundle key for specifying which user's app activity (moment) types can be written to Google.
 The list of activity types are represented as a space-separated string passed in the extras
 Bundle when calling <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle)">getToken(Context, String, String, Bundle)</a></code>.

 <p>
 This bundle key should be included in the extras Bundle when calling
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle)">getToken(Context, String, String, Bundle)</a></code> and should only be used when
 requesting the <code><a href="../../../../../../reference/com/google/android/gms/common/Scopes.html#PLUS_LOGIN">PLUS_LOGIN</a></code> OAuth 2.0 scope.

 See <a href="https://developers.google.com/+/api/moment-types">Types of moments</a>
 for the full list of valid activity types. Example usage:
 <pre>
     Bundle bundle = new Bundle();
     bundle.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
              "http://schemas.google.com/AddActivity http://schemas.google.com/BuyActivity");
     String token = GoogleAuthUtil.getToken(context, accountName, Scopes.PLUS_LOGIN, bundle);
 </pre>
</p></div>

    
        <div class="jd-tagdata">
        <span class="jd-tagtitle">Constant Value: </span>
        <span>
            
                "request_visible_actions"
            
        </span>
        </div>
    
    </div>
</div>




<!-- Fields -->


<!-- Public ctors -->



<!-- ========= CONSTRUCTOR DETAIL ======== -->
<!-- Protected ctors -->



<!-- ========= METHOD DETAIL ======== -->
<!-- Public methdos -->

<h2>Public Methods</h2>



<A NAME="getToken(android.content.Context, java.lang.String, java.lang.String)"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
         
         
         
        <a href="http://developer.android.com/reference/java/lang/String.html">String</a>
      </span>
      <span class="sympad">getToken</span>
      <span class="normal">(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope)</span>
    </h4>
      <div class="api-level">
        <div></div>
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p>Authenticates the user and returns a valid Google authentication token,
 or throws an exception if there was an error getting a token.
 <p>
 The exception thrown depends upon the underlying error and support for
 recovery. <code><a href="../../../../../../http://developer.android.com/reference/java/io/IOException.html">IOException</a></code>s will be thrown if the underlying error
 might be solved by some intelligent retry strategy. Alternatively,
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></code>s represent a broad class of
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code>s that cannot be recovered from programmatically. Some
 may be fatal errors stemming from implementation errors while others may
 require user intervention. <code><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableAuthException.html">UserRecoverableAuthException</a></code>s are
 GoogleAuthExceptions that provide <code><a href="../../../../../../http://developer.android.com/reference/android/content/Intent.html">Intent</a></code>s which can be used to
 initiate any user intervention required to fix the underlying error. For
 example, a UserRecoverableAuthExceptions intent might lead to a request
 for a user's consent or present the user with a device policy manager
 download screen. <code><a href="../../../../../../reference/com/google/android/gms/auth/GooglePlayServicesAvailabilityException.html">GooglePlayServicesAvailabilityException</a></code>s are
 UserRecoverableAuthExceptions along with a connection status code which
 allows clients to create a localized <code><a href="../../../../../../http://developer.android.com/reference/android/app/Dialog.html">Dialog</a></code> using
 <code><a href="../../../../../../reference/com/google/android/gms/common/GooglePlayServicesUtil.html#getErrorDialog(int, android.app.Activity, int)">getErrorDialog(int, android.app.Activity, int)</a></code>.
 Finally, this method is blocking and shouldn't be called in the main
 event thread. If so an <code><a href="../../../../../../http://developer.android.com/reference/java/lang/IllegalStateException.html">IllegalStateException</a></code> will be thrown.
 <p>
 Which exceptions should be handled and how depends on the context of the
 code. For example in the case of an <code><a href="../../../../../../http://developer.android.com/reference/android/app/Activity.html">Activity</a></code> where
 the user is actively engaged:

 <pre>
 String token;
 try {
     token = GoogleAuthUtil.getToken(context, accountName, scope);
 } catch (GooglePlayServicesAvailabilityException playEx) {
     Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
         playEx.getConnectionStatusCode(),
         Activity.this,
         AUTH_REQUEST_CODE);
     // Use the dialog to present to the user.
 } catch (UserRecoverableAutException recoverableException) {
     Intent recoveryIntent = recoverableException.getIntent();
     // Use the intent in a custom dialog or just startActivityForResult.
 } catch (GoogleAuthException authEx) {
     // This is likely unrecoverable.
     Log.e(TAG, "Unrecoverable authentication exception: " + authEx.getMesssage(), authEx);
 } catch (IOException ioEx) {
     Log.i(TAG, "transient error encountered: " + ioEx.getMessage());
     doExponentialBackoff();
 }
 </pre>

 On the other hand, explicitly handling a
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GooglePlayServicesAvailabilityException.html">GooglePlayServicesAvailabilityException</a></code> in the absence of a UI
 thread may not be worthwhile.  Instead a <code><a href="../../../../../../http://developer.android.com/reference/android/app/Notification.html">Notification</a></code>
 may be preferable.

 <pre>
 String token;
 try {
     token = GoogleAuthUtil.getToken(context, accountName, scope);
 } catch (UserRecoverableAuthException recoverableException) {
     Intent recoveryIntent = recoverableException.getIntent();
     // Use the intent to create a Notification.
 } catch (GoogleAuthException authEx) {
     // This is likely unrecoverable.
     Log.e(TAG, "Unrecoverable authentication exception: " + authEx.getMessage(), authEx);
 } catch (IOException ioEx) {
     Log.i(TAG, "transient error encountered: " + ioEx.getMessage());
     doExponentialBackoff();
 }
 </pre></p></div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Parameters</h5>
      <table class="jd-tagtable">
        <tr>
          <th>context</td>
          <td>Context associated with the desired token.</td>
        </tr>
        <tr>
          <th>accountName</td>
          <td>String representing the authenticating user account.</td>
        </tr>
        <tr>
          <th>scope</td>
          <td>String representing the authentication scope. To specify multiple scopes,
        separate them with a space (for example, "oauth2:scope1 scope2 scope3").</td>
        </tr>
      </table>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Returns</h5>
      <ul class="nolist"><li>String containing a valid token.</li></ul>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Throws</h5>
      <table class="jd-tagtable">  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/GooglePlayServicesAvailabilityException.html">GooglePlayServicesAvailabilityException</a></td>
            <td>containing the appropriate
         connection status error code.</td>
        </tr>  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableAuthException.html">UserRecoverableAuthException</a></td>
            <td>wrapping an Intent for initiating
         user intervention. The wrapped intent must be called with <code><a href="../../../../../../http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)">startActivityForResult(Intent, int)</a></code>.</td>
        </tr>  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></td>
            <td>signaling a potentially unrecoverable
         authentication error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/io/IOException.html">IOException</a></td>
            <td>signaling a potentially transient error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/lang/IllegalArgumentException.html">IllegalArgumentException</a></td>
            <td>if the method is invoked in the main
         event thread.
</td>
        </tr>
      </table>
  </div>

    </div>
</div>


<A NAME="getToken(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle)"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
         
         
         
        <a href="http://developer.android.com/reference/java/lang/String.html">String</a>
      </span>
      <span class="sympad">getToken</span>
      <span class="normal">(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> extras)</span>
    </h4>
      <div class="api-level">
        <div></div>
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p>Authenticates the user and returns a valid Google authentication token, or throws an
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code> if there was an error while getting the token.
 <p>
 The exception thrown depends upon the underlying error and support for
 recovery. <code><a href="../../../../../../http://developer.android.com/reference/java/io/IOException.html">IOException</a></code>s will be thrown if the underlying error
 might be solved by some intelligent retry strategy. Alternatively,
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></code>s represent a broad class of
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code>s that cannot be recovered from programmatically. Some
 may be fatal errors stemming from implementation errors while others may
 require user intervention. <code><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableAuthException.html">UserRecoverableAuthException</a></code>s are
 GoogleAuthExceptions that provide <code><a href="../../../../../../http://developer.android.com/reference/android/content/Intent.html">Intent</a></code>s which can be used to
 initiate any user intervention required to fix the underlying error. For
 example, a UserRecoverableAuthExceptions intent might lead to a request
 for a user's consent or present the user with a device policy manager
 download screen. <code><a href="../../../../../../reference/com/google/android/gms/auth/GooglePlayServicesAvailabilityException.html">GooglePlayServicesAvailabilityException</a></code>s are
 UserRecoverableAuthExceptions along with a connection status code which
 allows clients to create a localized <code><a href="../../../../../../http://developer.android.com/reference/android/app/Dialog.html">Dialog</a></code> using
 <code><a href="../../../../../../reference/com/google/android/gms/common/GooglePlayServicesUtil.html#getErrorDialog(int, android.app.Activity, int)">getErrorDialog(int, android.app.Activity, int)</a></code>.
 Finally, this method is blocking and shouldn't be called in the main
 event thread. If so an <code><a href="../../../../../../http://developer.android.com/reference/java/lang/IllegalStateException.html">IllegalStateException</a></code> will be thrown.
 <p>
 Which exceptions should be handled and how depends on the context of the
 code. For example in the case of an <code><a href="../../../../../../http://developer.android.com/reference/android/app/Activity.html">Activity</a></code> where
 the user is actively engaged:

 <pre>
 String token;
 try {
     token = GoogleAuthUtil.getToken(context, accountName, scope, bundle);
 } catch (GooglePlayServicesAvailabilityException playEx) {
     Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
         playEx.getConnectionStatusCode(),
         Activity.this,
         AUTH_REQUEST_CODE);
     // Use the dialog to present to the user.
 } catch (UserRecoverableAutException recoverableException) {
     Intent recoveryIntent = recoverableException.getIntent();
     // Use the intent in a custom dialog or just startActivityForResult.
 } catch (GoogleAuthException authEx) {
     // This is likely unrecoverable.
     Log.e(TAG, "Unrecoverable authentication exception: " + authEx.getMesssage(), authEx);
 } catch (IOException ioEx) {
     Log.i(TAG, "transient error encountered: " + ioEx.getMessage());
     doExponentialBackoff();
 }
 </pre>

 On the other hand, explicitly handling a
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GooglePlayServicesAvailabilityException.html">GooglePlayServicesAvailabilityException</a></code> in the absence of a UI
 thread may not be worthwhile.  Instead a <code><a href="../../../../../../http://developer.android.com/reference/android/app/Notification.html">Notification</a></code>
 may be preferable.

 <pre>
 String token;
 try {
     token = GoogleAuthUtil.getToken(context, accountName, scope, bundle);
 } catch (UserRecoverableAutException recoverableException) {
     Intent recoveryIntent = recoverableException.getIntent();
     // Use the intent to create a Notification.
 } catch (GoogleAuthException authEx) {
     // This is likely unrecoverable.
     Log.e(TAG, "Unrecoverable authentication exception: " + authEx.getMesssage(), authEx);
 } catch (IOException ioEx) {
     Log.i(TAG, "transient error encountered: " + ioEx.getMessage());
     doExponentialBackoff();
 }
 </pre></p></div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Parameters</h5>
      <table class="jd-tagtable">
        <tr>
          <th>context</td>
          <td>Context associated with the desired token.</td>
        </tr>
        <tr>
          <th>accountName</td>
          <td>String representing the authenticating user account.</td>
        </tr>
        <tr>
          <th>scope</td>
          <td>String representing the authentication scope.  To specify multiple scopes,
        separate them with a space (for example, "oauth2:scope1 scope2 scope3").</td>
        </tr>
        <tr>
          <th>extras</td>
          <td>Bundle containing additional information that may be
               relevant to the authentication scope.</td>
        </tr>
      </table>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Returns</h5>
      <ul class="nolist"><li>String containing a valid token.</li></ul>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Throws</h5>
      <table class="jd-tagtable">  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/GooglePlayServicesAvailabilityException.html">GooglePlayServicesAvailabilityException</a></td>
            <td>containing the appropriate
         connection status error code.</td>
        </tr>  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableAuthException.html">UserRecoverableAuthException</a></td>
            <td>wrapping an Intent for initiating
         user intervention. The wrapped intent must be called with <code><a href="../../../../../../http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)">startActivityForResult(Intent, int)</a></code>.</td>
        </tr>  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></td>
            <td>signaling a potentially unrecoverable
         authentication error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/io/IOException.html">IOException</a></td>
            <td>signaling a potentially transient error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/lang/IllegalArgumentException.html">IllegalArgumentException</a></td>
            <td>if the method is invoked in the main
         event thread.
</td>
        </tr>
      </table>
  </div>

    </div>
</div>


<A NAME="getTokenWithNotification(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle)"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
         
         
         
        <a href="http://developer.android.com/reference/java/lang/String.html">String</a>
      </span>
      <span class="sympad">getTokenWithNotification</span>
      <span class="normal">(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> extras)</span>
    </h4>
      <div class="api-level">
        <div></div>
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p>Authenticates the user and returns a valid Google authentication token, or throws an
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code> if there was an error while getting the token.
 <p>
 This method is specifically provided for background tasks. In the event of an error that
 needs user intervention, this method takes care of pushing relevant notification.
 <p>
 The exception thrown depends upon the underlying error and support for
 recovery. <code><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableNotifiedException.html">UserRecoverableNotifiedException</a></code> will be thrown if the error can be
 resolved by user intervention and a notification has already been posted to address it.
 <code><a href="../../../../../../http://developer.android.com/reference/java/io/IOException.html">IOException</a></code>s will be thrown if the underlying error
 might be solved by some intelligent retry strategy. Alternatively,
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></code>s represent a broad class of
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code>s that cannot be recovered programmatically.

 <pre>
 String token;
 try {
     token = GoogleAuthUtil.getToken(context, accountName, scope, callback, bundle);
 } catch (UserRecoverableNotifiedException userNotifiedException) {
     // Notification has already been pushed.
     // Continue without token or stop background task.
 } catch (GoogleAuthException authEx) {
     // This is likely unrecoverable.
     Log.e(TAG, "Unrecoverable authentication exception: " + authEx.getMesssage(), authEx);
 } catch (IOException ioEx) {
     Log.i(TAG, "transient error encountered: " + ioEx.getMessage());
     doExponentialBackoff();
 }
 </pre></p></div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Parameters</h5>
      <table class="jd-tagtable">
        <tr>
          <th>context</td>
          <td>Context associated with the desired token.</td>
        </tr>
        <tr>
          <th>accountName</td>
          <td>String representing the authenticating user account.</td>
        </tr>
        <tr>
          <th>scope</td>
          <td>String representing the authentication scope.  To specify multiple scopes,
        separate them with a space (for example, "oauth2:scope1 scope2 scope3").</td>
        </tr>
        <tr>
          <th>extras</td>
          <td>Bundle containing additional information that may be
               relevant to the authentication scope.</td>
        </tr>
      </table>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Returns</h5>
      <ul class="nolist"><li>String containing a valid token.</li></ul>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Throws</h5>
      <table class="jd-tagtable">  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableNotifiedException.html">UserRecoverableNotifiedException</a></td>
            <td>if a user addressable error occurred and a
         notification was pushed.</td>
        </tr>  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></td>
            <td>signaling a potentially unrecoverable
         authentication error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/io/IOException.html">IOException</a></td>
            <td>signaling a potentially transient error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/lang/IllegalArgumentException.html">IllegalArgumentException</a></td>
            <td>if the method is invoked in the main
         event thread.
</td>
        </tr>
      </table>
  </div>

    </div>
</div>


<A NAME="getTokenWithNotification(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle, android.content.Intent)"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
         
         
         
        <a href="http://developer.android.com/reference/java/lang/String.html">String</a>
      </span>
      <span class="sympad">getTokenWithNotification</span>
      <span class="normal">(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> extras, <a href="http://developer.android.com/reference/android/content/Intent.html">Intent</a> callback)</span>
    </h4>
      <div class="api-level">
        <div></div>
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p>Authenticates the user and returns a valid Google authentication token, or throws an
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code> if there was an error while getting the token.
 <p>
 This method is specifically provided for background tasks. In the event of an error that
 needs user intervention, this method takes care of pushing relevant notification. After the
 user addresses the notification, the callback is broadcasted. If the user cancels then the
 callback is not fired.
 <p>
 The exception thrown depends upon the underlying error and support for
 recovery. <code><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableNotifiedException.html">UserRecoverableNotifiedException</a></code> will be thrown if the error can be
 resolved by user intervention and a notification has already been posted to address it.
 <code><a href="../../../../../../http://developer.android.com/reference/java/io/IOException.html">IOException</a></code>s will be thrown if the underlying error
 might be solved by some intelligent retry strategy. Alternatively,
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></code>s represent a broad class of
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code>s that cannot be recovered programmatically.

 <pre>
 String token;
 try {
     token = GoogleAuthUtil.getToken(context, accountName, scope, callback, bundle);
 } catch (UserRecoverableNotifiedException userNotifiedException) {
     // Notification has already been pushed.
     // Continue without token or stop background task.
 } catch (GoogleAuthException authEx) {
     // This is likely unrecoverable.
     Log.e(TAG, "Unrecoverable authentication exception: " + authEx.getMesssage(), authEx);
 } catch (IOException ioEx) {
     Log.i(TAG, "transient error encountered: " + ioEx.getMessage());
     doExponentialBackoff();
 }
 </pre></p></div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Parameters</h5>
      <table class="jd-tagtable">
        <tr>
          <th>context</td>
          <td>Context associated with the desired token.</td>
        </tr>
        <tr>
          <th>accountName</td>
          <td>String representing the authenticating user account.</td>
        </tr>
        <tr>
          <th>scope</td>
          <td>String representing the authentication scope.  To specify multiple scopes,
        separate them with a space (for example, "oauth2:scope1 scope2 scope3").</td>
        </tr>
        <tr>
          <th>extras</td>
          <td>Bundle containing additional information that may be
               relevant to the authentication scope.</td>
        </tr>
        <tr>
          <th>callback</td>
          <td>A broadcast intent with a valid receiver that has been exported for other
     apps to send broadcasts to it. This intent must be serializable using
     toUri(Intent.URI_INTENT_SCHEME) and Intent.parseUri(intentUri, Intent.URI_INTENT_SCHEME).
     Cannot be null.</td>
        </tr>
      </table>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Returns</h5>
      <ul class="nolist"><li>String containing a valid token.</li></ul>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Throws</h5>
      <table class="jd-tagtable">  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableNotifiedException.html">UserRecoverableNotifiedException</a></td>
            <td>if a user addressable error occurred and a
         notification was pushed.</td>
        </tr>  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></td>
            <td>signaling a potentially unrecoverable
         authentication error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/io/IOException.html">IOException</a></td>
            <td>signaling a potentially transient error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/lang/IllegalArgumentException.html">IllegalArgumentException</a></td>
            <td>if the method is invoked in the main
         event thread.
</td>
        </tr>
      </table>
  </div>

    </div>
</div>


<A NAME="getTokenWithNotification(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle, java.lang.String, android.os.Bundle)"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
         
         
         
        <a href="http://developer.android.com/reference/java/lang/String.html">String</a>
      </span>
      <span class="sympad">getTokenWithNotification</span>
      <span class="normal">(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> accountName, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> scope, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> extras, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> authority, <a href="http://developer.android.com/reference/android/os/Bundle.html">Bundle</a> syncBundle)</span>
    </h4>
      <div class="api-level">
        <div></div>
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p>Authenticates the user and returns a valid Google authentication token, or throws an
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code> if there was an error while getting the token.
 <p>
 This method is specifically provided for sync adaptors. In the event of an error that
 needs user intervention, this method takes care of pushing relevant notification. After the
 user addresses the notification, a sync request will be kicked off using the given params.
 If the user cancels then the sync is not fired.
 <p>
 The exception thrown depends upon the underlying error and support for
 recovery. <code><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableNotifiedException.html">UserRecoverableNotifiedException</a></code> will be thrown if the error can be
 resolved by user intervention and a notification has already been posted to address it.
 <code><a href="../../../../../../http://developer.android.com/reference/java/io/IOException.html">IOException</a></code>s will be thrown if the underlying error
 might be solved by some intelligent retry strategy. Alternatively,
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></code>s represent a broad class of
 <code><a href="../../../../../../http://developer.android.com/reference/java/lang/Exception.html">Exception</a></code>s that cannot be recovered programmatically.

 <pre>
 String token;
 try {
     token = GoogleAuthUtil.getToken(
         context, accountName, scope, authority, syncBundle, bundle);
 } catch (UserRecoverableNotifiedException userNotifiedException) {
     // Notification has already been pushed.
     // Continue without token or stop background task.
 } catch (GoogleAuthException authEx) {
     // This is likely unrecoverable.
     Log.e(TAG, "Unrecoverable authentication exception: " + authEx.getMesssage(), authEx);
 } catch (IOException ioEx) {
     Log.i(TAG, "transient error encountered: " + ioEx.getMessage());
     doExponentialBackoff();
 }
 </pre></p></div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Parameters</h5>
      <table class="jd-tagtable">
        <tr>
          <th>context</td>
          <td>Context associated with the desired token.</td>
        </tr>
        <tr>
          <th>accountName</td>
          <td>String representing the authenticating user account.</td>
        </tr>
        <tr>
          <th>scope</td>
          <td>String representing the authentication scope.  To specify multiple scopes,
        separate them with a space (for example, "oauth2:scope1 scope2 scope3").</td>
        </tr>
        <tr>
          <th>extras</td>
          <td>Bundle containing additional information that may be
               relevant to the authentication scope.</td>
        </tr>
        <tr>
          <th>authority</td>
          <td>Authority for firing a sync request. Must not be empty or null.</td>
        </tr>
        <tr>
          <th>syncBundle</td>
          <td>extras for firing a sync request. This bundle must pass
     ContentResolver.validateSyncExtrasBundle(). If no extras are needed can a null value
     can be passed.</td>
        </tr>
      </table>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Returns</h5>
      <ul class="nolist"><li>String containing a valid token.</li></ul>
  </div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Throws</h5>
      <table class="jd-tagtable">  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/UserRecoverableNotifiedException.html">UserRecoverableNotifiedException</a></td>
            <td>if a user addressable error occurred and a
         notification was pushed.</td>
        </tr>  
        <tr>
            <th><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthException.html">GoogleAuthException</a></td>
            <td>signaling a potentially unrecoverable
         authentication error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/io/IOException.html">IOException</a></td>
            <td>signaling a potentially transient error.</td>
        </tr>  
        <tr>
            <th><a href="http://developer.android.com/reference/java/lang/IllegalArgumentException.html">IllegalArgumentException</a></td>
            <td>if the method is invoked in the main
         event thread.
</td>
        </tr>
      </table>
  </div>

    </div>
</div>


<A NAME="invalidateToken(android.content.Context, java.lang.String)"></A>

<div class="jd-details api apilevel-"> 
    <h4 class="jd-details-title">
      <span class="normal">
        public 
        static 
         
         
         
        void
      </span>
      <span class="sympad">invalidateToken</span>
      <span class="normal">(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, <a href="http://developer.android.com/reference/java/lang/String.html">String</a> token)</span>
    </h4>
      <div class="api-level">
        <div></div>
        
  

      </div>
    <div class="jd-details-descr">
      
  <div class="jd-tagdata jd-tagdescr"><p>Invalidates the specified token with respect to the <code><a href="../../../../../../http://developer.android.com/reference/android/content/Context.html">Context</a></code>.
 Note that the context must be the same as that used to initialize
 the token in a previous call to
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context, java.lang.String, java.lang.String)">getToken(Context, String, String)</a></code> or
 <code><a href="../../../../../../reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context, java.lang.String, java.lang.String, android.os.Bundle)">getToken(Context, String, String, Bundle)</a></code>.</p></div>
  <div class="jd-tagdata">
      <h5 class="jd-tagtitle">Parameters</h5>
      <table class="jd-tagtable">
        <tr>
          <th>context</td>
          <td>Context of the token.</td>
        </tr>
        <tr>
          <th>token</td>
          <td>String containing the token to invalidate.
</td>
        </tr>
      </table>
  </div>

    </div>
</div>





<!-- ========= METHOD DETAIL ======== -->



<!-- ========= END OF CLASS DATA ========= -->
<A NAME="navbar_top"></A>

<div id="footer" class="wrap" >
        

  <div id="copyright">
    
  Except as noted, this content is licensed under <a
  href="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0</a>. 
  For details and restrictions, see the <a href="../../../../../../license.html">
  Content License</a>.
  </div>
  <div id="build_info">
    
    Android &nbsp;r &mdash; 25 Feb 2013 22:22

  </div>


  <div id="footerlinks">
    
  <p>
    <a href="../../../../../../about/index.html">About Android</a>&nbsp;&nbsp;|&nbsp;
    <a href="../../../../../../legal.html">Legal</a>&nbsp;&nbsp;|&nbsp;
    <a href="../../../../../../support.html">Support</a>
  </p>
  </div>

</div> <!-- end footer -->
</div> <!-- jd-content -->

</div><!-- end doc-content -->

</div> <!-- end body-content --> 




<!-- Grid - for dev 
<script type="text/javascript">

window.gOverride = {
		gColor: '#FF0000',
		pColor: '#EEEEEE',
		gOpacity: 0.10,
		pOpacity: 0.40,
		pHeight: 16,
		pOffset: 2,
		gColumns:16,
		gEnabled:false,
		pEnabled:false
	}
</script>
	
<link href="../../../../../../assets/js/grid/960.gridder.css" rel="stylesheet" type="text/css">
<script src="../../../../../../assets/js/grid/960.gridder.js" type="text/javascript"></script>
-->





<script type="text/javascript">
init(); /* initialize android-developer-docs.js */
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
  var pageTracker = _gat._getTracker("UA-5831155-1");
  pageTracker._trackPageview();
</script>



</body>
</html>
